// pages/user/recommend/deposit/deposit.js
const config = getApp().globalData.config
const T = getApp().globalData.T
let token = ''
Page({

  /**
   * 页面的初始数据
   */
  data: {
    price: 0,
    canDepositPrice: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    token = getApp().globalData.token;
    this.getDetail();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  onInputPrice(e) {
    this.setData({
      price: e.detail.value
    })
  },

  onFillPrice() {
    this.setData({
      price: this.data.canDepositPrice
    })
  },

  getDetail() {
    T.req({
      loadTitle: '初始化中...',
      url: config.api + 'recommendation/point',
      method: 'GET',
      data: {
        token: token
      },
      success: (res) => {
        this.setData({
          reward: res.reward
        })
      }
    })
  },

  /**
   * 提现
   */
  onDepositBtn() {
    if (!T.trim(this.data.price.toString()) || this.data.price == 0 || this.data.price > this.data.canDepositPrice) return;
    let param = {
      openid: getApp().globalData.userId,
      money: this.data.price
    }
    T.req({
      loadTitle: '请求中...',
      url: config.api + 'pay/withdrawal?token=' + token,
      method: 'POST',
      success: (res) => {
        this.setData({
          reward: res.reward
        })
      }
    })
  }
})